package com.paradogs.framework.core.msg;

import com.baidu.bjf.remoting.protobuf.FieldType;
import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.io.IOException;
import java.util.Arrays;

/**
 * @author: yumi
 * @date: 2023/8/7  9:52
 * @Description: TODO
 */
@Data
public class ByteData implements IMsgSerializable {

    @Protobuf(fieldType = FieldType.OBJECT, order = 1)
    private MsgHeader msgHeader;

    @Protobuf(fieldType = FieldType.BYTES, order = 2)
    private byte[] dataBytes;


    private PRMsgContextHolder.Snapshot context;

    @Override
    public void serialization(ByteBuf out) {
        out.writeBytes(this.dataBytes);
    }

    @Override
    public void deserialization(ByteBuf in) throws IOException {
        this.dataBytes =  new byte[in.readableBytes()];
        in.readBytes(this.dataBytes);
    }

    @Override
    public void deserialization(byte[] bytes) throws IOException {
        this.dataBytes = bytes;
    }

}
